﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;

namespace ATM
{
    public partial class vantin : Form
    {
        private SqlConnection con;
        private SqlCommand cmd,cmd1;
        private SqlDataReader reader;
        public vantin(string s)
        {
            InitializeComponent();
            label3.Text = s;
        }

        private void vantin_Load(object sender, EventArgs e)
        {
            string conStr = ConfigurationManager.ConnectionStrings["conStr"].ConnectionString;
            con = new SqlConnection(conStr);
            cmd = new SqlCommand("select Acc_Balance from TB_ACCOUNT where Acc_No='" + label3.Text + "'", con);
            con.Open();
            reader = cmd.ExecuteReader();
            reader.Read();
            label5.Text = reader.GetValue(0).ToString();
            label7.Text = DateTime.Now.ToShortDateString();
            con.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            cmd = new SqlCommand("select Acc_ID from TB_ACCOUNT where Acc_No='" + label3.Text + "'", con);
            con.Open();
            reader = cmd.ExecuteReader();
            reader.Read();
            string s = reader.GetValue(0).ToString();
            con.Close();
            cmd1 = new SqlCommand("insert into TB_TRANSACTION(Tran_Type,Acc_Pri_ID,Tran_Amount,Tran_Balance,Tran_Date) values (3,'" + s + "',0,'"+label5.Text+"','" + label7.Text + "')", con);

            con.Open();
            cmd1.ExecuteNonQuery();
          //  MessageBox.Show("OK");
            con.Close();
            main f = new main(label3.Text);
            f.Show();
            this.Hide();
        }
    }
}
